package com.zpark.controller;

import com.zpark.beans.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xiaoyu
 * @version 1.0 2022/8/25
 *
 * @RestController = @Controller + @ResponseBody
 * 用于返回 json 格式数据
 */

@RestController
//@Controller
@RequestMapping("/config")
public class ConfigController {

    //自动注入
    @Autowired
    private Person person;

    //使用 value 注解获取配置
    @Value("${server.port}") //SpEl 表达式
    private String port;

    @Value("${username}")
    private String username;
    @Value("${person.username}")
    private String uname;


    //声明当前方法返回 json 格式数据
//    @ResponseBody
    @RequestMapping("/person")
    public Person getPerson() {
        return person;
    }

    @RequestMapping("/port")
    public String getPort() {
        return port;
    }

    @RequestMapping("/username")
    public String getUsername() {
        return username;
    }
    @RequestMapping("/uname")
    public String getUname() {
        return uname;
    }

}
